<%@page import="java.util.Date"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>JSP内置对象测试</title>
	</head>
	
	<%!
		public String param1;
		public String param2;
	%>
	
	<body>
	
	<%
	
		/*session是一个内置对象，用于进行与会话相关的操作*/
		out.print("会话编号：" + session.getId() + "<br>");
		out.print("会话创建时间：" + new Date(session.getCreationTime()) + "<br>");
		
		/*session可获取保存在会话中的相关属性*/
		out.print("属性attr1 = " + session.getAttribute("attr1") + "<br>");
		
		/*page对象代表页面本身，类似于Java类的this指针*/
		out.print("page对象的类型为：" + page.getClass() + "<br>");

		/*application对象代表当前Web应用的本身*/
		out.print(application.getServerInfo() + "<br>");
		
		out.print(pageContext.getServletContext() + "<br>");
		out.print(request.getServletContext() + "<br>");
		out.print(application + "<br>");
		
		/*使用pageContext内置对象将同名属性存储到不同的作用域*/
		pageContext.setAttribute("attr", "I am in the page!", PageContext.PAGE_SCOPE);
		pageContext.setAttribute("attr", "I am in the request!", PageContext.REQUEST_SCOPE);
		pageContext.setAttribute("attr", "I am in the session!", PageContext.SESSION_SCOPE);
		pageContext.setAttribute("attr", "I am in the application!", PageContext.APPLICATION_SCOPE);
		
		/*获取不同作用域内的同名属性*/
		out.print(pageContext.getAttribute("attr") + "<br>");
		out.print(request.getAttribute("attr") + "<br>");
		out.print(session.getAttribute("attr") + "<br>");
		out.print(application.getAttribute("attr") + "<br>");
		
	%>
	
	
	</body>
</html>
